package com.rex.sample.controller;

import javax.servlet.http.HttpServletRequest;

import com.rex.sample.service.SampleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/")
public class SampleController {
	
	@Autowired
	SampleService sampleService;
	
	@RequestMapping(value="/", method = RequestMethod.GET)
	public ModelAndView sayHello() {

		String hello = sampleService.sayHello();
		return new ModelAndView("message/test").addObject("msg", hello);
	}

	@RequestMapping(value="add/{para}", method = RequestMethod.GET)
	public ModelAndView addHello(@PathVariable String para, HttpServletRequest req) {

		sampleService.addHello(para);
		return new ModelAndView("message/test").addObject("msg", "Added");
	}


}
